<template>
  <div>
    <el-form ref="statusFormRef" :model="statusForm.data" label-width="120">
      <el-form-item label="使用状态">
        <el-select
          v-model="statusForm.data.status"
          filterable
          style="width: 320px"
          placeholder="请选择使用状态"
        >
          <el-option
            v-for="item in status.data"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <div class="reminder">
        <img class="icon-reminder" :src="iconReminder" alt="" />
        <div>
          <span style="margin-right: 6px">温馨提示：</span
          >仅当设备处于使用中，可进行泊位关联。若转为非使用中状态，则自动清除泊位关联。
        </div>
      </div>
      <div class="footer">
        <div></div>
        <div>
          <el-button class="reset-btn" @click="resetForm(statusFormRef)"
            >取 消</el-button
          >
          <el-button class="confirm-btn" @click="submitForm(statusFormRef)"
            >确 认</el-button
          >
        </div>
      </div>
    </el-form>
  </div>
</template>

<script setup>
import { reactive, ref, defineProps } from "vue";
import iconReminder from "@/assets/image/reminder.png";
import { getDictionary } from "@/service/modules/publicModule";
import { getStatusVideo } from "../request.js";

const props = defineProps({
  operationId: {
    type: Object,
    default: () => {},
  },
});

const status = reactive({
  data: [],
});

const statusFormRef = ref("");

const statusForm = reactive({
  data: {},
});

const getData = async () => {
  await getDictionary("device_use_state").then((res) => {
    status.data = res.data.result;
  });
};

getData();

const submitForm = (formEl) => {
  if (!formEl) return;
  formEl.validate((valid) => {
    if (valid) {
      getStatusVideo({
        data: props.operationId,
        status: statusForm.data.status,
      }).then((res) => {
        if (res.data.code === 0) {
          ElMessage({
            type: "success",
            message: res.data.result,
          });
          emits("operationDone");
        } else {
          ElMessage.error(res.data.msg);
        }
      });
    }
  });
};
const resetForm = (formEl) => {
  if (!formEl) return;
  statusForm.data = {};
  formEl.resetFields();
  emits("operationDone");
};
const emits = defineEmits(["operationDone"]);
</script>

<style lang="less" scoped>
.reminder {
  margin-left: 52px;
  background: #e1efff;
  border: 1px solid #81b8ff;
  border-radius: 2px;
  font-weight: 400;
  font-size: 14px;
  color: #333333;
  width: 388px;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  padding: 10px 12px;
  line-height: 1.5;
  .icon-reminder {
    width: 20px;
    height: 20px;
    margin: -20px 12px 0 9px;
  }
}
.footer {
  width: 100%;
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}
.reset-btn {
  width: 65px;
  height: 32px;
  background: #ffffff;
  border-radius: 2px;
  border: 1px solid #d9d9d9;
  font-weight: 400;
  font-size: 14px;
  color: rgba(0, 0, 0, 0.65);
}
.confirm-btn {
  width: 65px;
  height: 32px;
  background: #007aff;
  border-radius: 2px;
  font-weight: 400;
  font-size: 14px;
  color: #ffffff;
}
</style>